package com.ruoyi.wx.controller;


import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ScoreUtile;
import com.ruoyi.wx.entity.dto.QueAllDTO;
import com.ruoyi.wx.service.IPtQuestionService;
import com.ruoyi.wx.service.IPtScoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 实验题目表 前端控制器
 * </p>
 *
 * @author moxiu
 * @since 2022-03-04
 */
@RestController
@Api(value = "题目", tags = {"题目接口测试"})
@RequestMapping("/wx")
public class PtQuestionController {

    @Autowired
    private IPtScoreService iPtScoreService;

    @Autowired
    private IPtQuestionService ptQuestionService;

    @GetMapping("/getQueAll")
    @ApiOperation("获取该实验的全部题目")
    public AjaxResult<QueAllDTO> getQueAll(Long expId) {
        if (expId == null) {
            throw new SecurityException("实验id不能为空");
        }
        return AjaxResult.success(ptQuestionService.getQueAll(expId));
    }

    @GetMapping("/score")
    @ApiOperation("做完题目给分")
    public AjaxResult score(Long expId, Double score) {
        if (!ScoreUtile.checkScore(score)) {
            throw new SecurityException("分数在 0~100 之间");
        }
        return AjaxResult.success(iPtScoreService.createScore(expId, score));
    }

}
